package app.com.rtsplibrary.data;

import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingDeque;

public class ADataUtil {

    public LinkedBlockingDeque<H264Data> pcmData = new LinkedBlockingDeque<>(VDataUtil.queueSize);
    private static ArrayList<ADataUtil> dataList = new ArrayList<ADataUtil>();

    public ADataUtil(){
        dataList.add(this);
    }

    public static void putData(byte[] buffer, int type, long ts) {
        for(int i=0; i<dataList.size(); i++) {
            ADataUtil du = dataList.get(i);
            if (du.pcmData.size() >= VDataUtil.queueSize) {
                du.pcmData.poll();
            }
            H264Data data = new H264Data(buffer, type, ts);
            du.pcmData.add(data);
        }
    }

    public static void putData(H264Data data) {
        for(int i=0; i<dataList.size(); i++) {
            ADataUtil du = dataList.get(i);
            if (du.pcmData == null) {
                du.pcmData = new LinkedBlockingDeque<>(VDataUtil.queueSize);
            }
            if (du.pcmData.size() >= VDataUtil.queueSize) {
                du.pcmData.poll();
            }
            du.pcmData.add(data);
        }
    }

    public LinkedBlockingDeque<H264Data> getPcmData() {
        return pcmData;
    }

    public void close(){
        dataList.remove(this);
    }


}
